package com.tbit.main.pojo;/**
 * 车辆总数
 */

import cn.hutool.core.util.NumberUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.text.DecimalFormat;

/**
 * 车辆总数
 * <p>
 * 车辆总数
 * <p>
 * 车辆总数
 * <p>
 * 车辆总数
 * <p>
 * 车辆总数
 * <p>
 * 车辆总数
 * <p>
 * 车辆总数
 */
/**
 * 车辆总数
 */ /**
 * 车辆总数
 */

/**
 * 运维数据
 *
 * @author LMY
 * @create 2022-11-19 14:01
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Accessors(chain = true)
public class AccountDataMain {
    private static final DecimalFormat df = new DecimalFormat("0.00");
    /**
     * 骑行收入
     */
    private Double rideIncome;
    /**
     * 车辆总数 //最后一天
     */
    private Long machineSum;
    /**
     * 投放
     */
    private Long machineLaunch;
    /**
     * 未投放
     */
    private Long machineNotLaunch;
    /**
     * 可运营
     */
    private Long machineRun;
    /**
     * 不可运营
     */
    private Long machineNotRun;
    /**
     * 故障
     */
    private Long machineFault;
    /**
     * 车均订单
     */
    private Float machineOrder;
    /**
     * 车均金额
     */
    private Float machineMoney;
    /**
     * 行驶里程（KM）
     */
    private Long machineKM;
    /**
     * 节能减排（吨）
     */
    private Long machineTon;
    /**
     * 约等于种树（棵）
     */
    private Long machineTree;
    /**
     * 运维人员总数
     */
    private Long accountUserSum;
    /**
     * 换电总次数
     */
    private Long powerSum;
    /**
     * 人均换电次数
     */
    private Float powerAccountUser;
    /**
     * 挪车总次数
     */
    private Long moveSum;
    /**
     * 人均挪车次数
     */
    private Float moveAccountUser;
    /**
     * 调度总次数
     */
    private Long dispatchSum;
    /**
     * 人均调度次数
     */
    private Float dispatchAccountUser;
    /**
     * 运营区域面积（平方公里）
     */
    private Float accountArea;
    /**
     * 人口规模
     */
    private Long accountPeople;
    /**
     * 运营车辆密度（辆/平方百米）
     */
    private Float accountDensity;
    /**
     * 累计用户数
     */
    private Long userSum;
    /**
     * 新增用户数
     */
    private Long userNewSum;
    /**
     * 每日骑行用户数
     */
    private Long dailyRidingUser;
    /**
     * 巡检总数
     */
    private Long patrolSum;
    /**
     * 维修
     */
    private Long repairSum;
    /**
     * 摆车
     */
    private Long neatSum;
    /**
     * 超区
     */
    private Long machineOutRange;
    /**
     * 馈电
     */
    private Long machineFeed;
    /**
     * 站外
     */
    private Long machineOutSide;
    /**
     * 限制
     */
    private Long machineLimit;
    /**
     * 无信号
     */
    private Long machineNoSignal;
    /**
     * 闲置
     */
    private Long machineFree;

    /**
     * 最后计算未投放车辆总数 不可运营车辆数
     */
    public void compute() {
        //未投放车辆总数 = 可运营车辆总数 + 不可运营车辆总数
        machineNotLaunch = machineSum - machineLaunch;
        //车辆总数 = 投放车辆总数 + 未投放车辆总数
        machineNotRun = machineLaunch - machineRun;
    }

    /**
     * 计算碳排放
     */
    public void carbon(Long energy) {
        //电动车碳排放每公里55g，汽车碳排放每公里225g
        machineTon = energy / 1000 / 1000;
        //5023g碳排放约种一棵树
        machineTree = energy / 5023;
    }

    /**
     * 计算运营区域密度
     */
    public void density() {
        if (accountArea == 0f) {
            accountDensity = 0f;
        } else {
            accountDensity = Float.parseFloat(df.format((float) machineSum / accountArea));
        }
    }

    /**
     * 区域面积
     * @param area
     * @return
     */
    public Float area(Long area) {
        Float a = Float.parseFloat(df.format((float) area / 1000000));
        return a;
    }

    /**
     * 车均订单
     * @param orderCount 订单总数
     */
    public void calculateMachineOrderAvg(Long orderCount) {
        if (this.machineSum == 0) {
            this.machineOrder = 0.0f;
            return;
        }
        this.machineOrder = NumberUtil.div(orderCount, machineSum, 2).floatValue();
    }

    /**
     * 车辆收入
     * @param moneyIncomeSum 车辆总营收
     */
    public void calculateMachineMoneyAvg(Long moneyIncomeSum) {
        if (this.machineSum == 0) {
            this.machineMoney = 0.0f;
            return;
        }
        this.machineMoney = (float) NumberUtil.div(NumberUtil.div(moneyIncomeSum.longValue(), 100, 2), this.machineSum.longValue(), 2);
    }


    public void nullValueSetDefaultVal() {
        if (machineSum == null) {
            this.machineSum = 0L;
        }
        if (machineLaunch == null) {
            this.machineLaunch = 0L;
        }
        if (machineNotLaunch == null) {
            this.machineNotLaunch = 0L;
        }
        if (machineRun == null) {
            this.machineRun = 0L;
        }
        if (machineNotRun == null) {
            this.machineNotRun = 0L;
        }
        if (machineFault == null) {
            this.machineFault = 0L;
        }
        if (machineOrder == null) {
            this.machineOrder = 0.0f;
        }
        if (machineMoney == null) {
            this.machineMoney = 0.0f;
        }
        if (machineKM == null) {
            this.machineKM = 0L;
        }
        if (machineTon == null) {
            this.machineTon = 0L;
        }
        if (machineTree == null) {
            this.machineTree = 0L;
        }
        if (accountUserSum == null) {
            this.accountUserSum = 0L;
        }
        if (powerSum == null) {
            this.powerSum = 0L;
        }
        if (powerAccountUser == null) {
            this.powerAccountUser = 0.0F;
        }
        if (moveSum == null) {
            this.moveSum = 0L;
        }
        if (moveAccountUser == null) {
            this.moveAccountUser = 0.0F;
        }
        if (dispatchSum == null) {
            this.dispatchSum = 0L;
        }
        if (dispatchAccountUser == null) {
            this.dispatchAccountUser = 0.0F;
        }
        if (accountArea == null) {
            this.accountArea = 0.0f;
        }
        if (accountPeople == null) {
            this.accountPeople = 0L;
        }
        if (accountDensity == null) {
            this.accountDensity = 0.0f;
        }
        if (userSum == null) {
            this.userSum = 0L;
        }
        if (userNewSum == null) {
            this.userNewSum = 0L;
        }
        if (dailyRidingUser == null) {
            this.dailyRidingUser = 0L;
        }
        if (patrolSum == null) {
            this.patrolSum = 0L;
        }
        if (repairSum == null) {
            this.repairSum = 0L;
        }
        if (neatSum == null) {
            this.neatSum = 0L;
        }
        if (machineOutRange == null) {
            this.machineOutRange = 0L;
        }
        if (machineFeed == null) {
            this.machineFeed = 0L;
        }
        if (machineOutSide == null) {
            this.machineOutSide = 0L;
        }
        if (machineLimit == null) {
            this.machineLimit = 0L;
        }
        if (machineNoSignal == null) {
            this.machineNoSignal = 0L;
        }
        if (machineFree == null) {
            this.machineFree = 0L;
        }
    }

}
